<template>
	<div id="balance">
		<div id="header">
			<img @click="$router.go(-1)" src="../../static/img/return.png"/>
			<p>账户余额</p>
		</div>
		<!-----------可用余额--------------->
		<div class="balance_1">
			<div class="now">
				<p>可用余额</p>
				<p>¥<span>{{returnFloat(balance)}}</span></p>
			</div>
			<div class="future">
				<p>推广金<img @click="cue" src="../../static/img/balance-04.png" /></p>
				<p>¥<span>{{returnFloat(extendsBlance)}}</span></p>
			</div>
			<!--<div class="future">
				<p>即将到账<img @click="cue" src="../../static/img/balance-04.png" /></p>
				<p>¥<span>{{returnFloat(extendsUserComing+extendsOwnerComing)}}</span></p>
			</div>-->
		</div>
		<div class="balance_2">
			<div @click="selectMyCard">
				<p><img src="../../static/img/balance-02.png"/>提现</p>
				<img src="../../static/img/my-12.png"/>
			</div>
			<router-link to="/user/withdrawalList">
				<p><img src="../../static/img/balance-05.png"/>提现列表</p>
				<img src="../../static/img/my-12.png"/>
			</router-link>
			<router-link to="/user/stream">
				<p><img src="../../static/img/balance-03.png"/>账户明细</p>
				<img src="../../static/img/my-12.png"/>
			</router-link>
		</div>
	</div>
</template>

<script>
export default{
	name: 'balance',
	data:function(){
		return{
			balance: 0,//可用余额
			extendsBlance: 0,//推广金
			extendsUserComing:0,//推广用户即将到账
			extendsOwnerComing:0,//推广商家即将到账
		}
	},
	methods:{
		// -------- 获取余额 -----------
		getBalance: function(){
			var _this = this;
			_this.$axios.post("/user/wallet/getWalletInfo").then(function(res){
				var data = res.data;
				if(data.message == "succ"){
					_this.balance = data.result.balance;
					_this.extendsBlance = data.result.extendsBlance;
					_this.extendsUserComing = data.result.extendsUserComing;
					_this.extendsOwnerComing = data.result.extendsOwnerComing;
				}else{
					_this.$alert(data.result);
				}
			}).catch(function (error) {
				console.log(error);
			});
		},
		//------------提示-----------------
		cue:function(){
			this.$alert('通过推广获得的现金,无需完成首单即可提现');
		},
		//--------小数点后两位不够补零---------------
		returnFloat:function(value){
			var value=Math.round(parseFloat(value)*100)/100;
			var xsd=value.toString().split(".");
			if(xsd.length==1){
				value=value.toString()+".00";
				return value;
			}
			if(xsd.length>1){
				if(xsd[1].length<2){
					value=value.toString()+"0";
				}
				return value;
			}
		},
		//---------获取我的银行卡-------------
	    selectMyCard: function(){
	    	var _this = this;
	    	_this.$axios.post("/user/bankCard/getUserCard").then(function(res){
	    		var data = res.data;
	    		if(data.message == "succ"){
	    			data = data.result;
	    			if(data.length == 0){
		    			/*_this.$alert("您还未绑定银行卡，是否前往绑定", function(){
		    				_this.$router.push('/user/bankcard');
		    			});*/
		    			_this.$router.push('/user/withdrawal');
		    		}else{
		    			_this.$router.push('/user/withdrawal');
		    		}
	    		}else{
	    			console.log(data.result);
	    		}
	    	}).catch(function(err){
	    		console.log(err);
	    	});
	    	
	    },
	},
	created: function(){
		this.getBalance();
	}
}
</script>

<style scoped>
/* ========== */
/* = Header = */
/* ========== */
#header{
	width: 100%;
	background-color: #fff;
	position: fixed;
	top: 0;
	left: 0;
	height: 4rem;
	display: flex;
	align-items: center;
	justify-content: center;
	border-bottom: 1px solid #EEEEEE;
	font-size: 1.6rem;
	color: #4F4F4F;
	box-sizing: border-box;
	z-index: 10;
}
#header img{
	height: 2rem;
	display: block;
	position: absolute;
	top: 1rem;
	left: 2rem;
}
#balance{
	height: 100%;
	padding-top: 4rem;
	box-sizing: border-box;
	background-color: #fff;
}
/*----------可用余额------------*/
.balance_1{
	background: url('../../static/img/balance-01.png') no-repeat;
	background-size: 100% 100%;
	height: 10rem;
	display: flex;
	align-items: center;
	color: #FFFFFF;
}
.balance_1>div{
	width: 50%;
	height: 100%;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}
.balance_1 p{
	font-size: 1.4rem;
}
.now p:first-child{
	margin-bottom: 1rem;
}
.future p:first-child{
	margin-bottom: 0.6rem;
	display: flex;
	align-items: center;
	padding-left: 1.5rem;
	color: #FFFAAE;
}
.future p:last-child{
	color: #FFFAAE;
}
.balance_1 img{
	height: 1.2rem;
	display: block;
	margin-left: 0.5rem;
}
.now p span{
	font-size: 2.4rem;
	margin-left: 0.3rem;
}
.future p span{
	font-size: 2.2rem;
	margin-left: 0.3rem;
}
.balance_2 a, .balance_2>div{
	display: flex;
	align-items: center;
	justify-content: space-between;
	border-bottom: 1px solid #EEEEEE;
	height: 3.6rem;
	padding: 0 1rem;
}
.balance_2>div{
	padding: 0 0.5rem 0 1rem;
}
.balance_2 a p, .balance_2>div p{
	display: flex;
	align-items: center;
	font-size: 1.4rem;
	color: #4F4F4F;
	white-space: nowrap;
}
.balance_2 a p img, .balance_2>div img{
	height: 1.4rem;
	display: block;
	margin-right: 0.5rem;
}
.balance_2 a>img, .balance_2>div>img{
	height: 1rem;
	display: block;
}

</style>
